In [1]:
from IPython.display import HTML

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Magic Button."></form>''')
Out[1]:
In [2]:
from plotly import graph_objs as go
from plotly.offline import iplot, init_notebook_mode
import numpy as np
init_notebook_mode()
def plot_multiple(Xs,Ys):
    assert len(Xs) == len(Ys)
    traces = [go.Scatter(x=Xs[i], y = Ys[i], mode = 'lines') for i in range(len(Xs))] 
    iplot(traces)
def plotit(x,y):
    trace1 = go.Scatter(x = x, y = y , mode='lines', name = 'f(x)')
    iplot([trace1])

Exponential functions

$$ f(x) = 3^x$$ $$ g(x) = (1/2)^x$$ $$ h(x) = (4/3)^x$$

Exponent Review

  1. $$2^3$$
  2. $$3^{-1}$$
  3. $$16^{1/2}$$

Exponential Growth

Exponential functions with base >1 get very big very quickly for large inputs, and get very small very quickly on small inputs.

Domain and Range of an Exponential Function

$$f(x) = 2^x$$

Domain: all x

Range: $f(x) > 0$

$$ y = 3^x$$

x y
-3 $3^{-3}$
-2 $3^{-2}$
-1 $3^{-1}$
0 $3^{0}$
1 $3^{1}$
2 $3^{2}$
3 $3^{3}$
x y  
-3 $1/27$
-2 $1/9$
-1 $1/3$
0 $1$
1 $3$
2 $9$
3 $27$
4 81
5 243
In [3]:
x = np.arange(-5,5,.1)
y = 3**x
plotit(x,y)

Exponents in the real world

"Compound interest is the eight wonder of the world"

(Probably a fake quote, but a good lesson anyway)

  • Finance investing
  • Population Growth
  • Radioactive Decay

Group Problem

Brandon invests €10000 into his retirement account. Every year, his account grows by 6%

  1. How much money will he have if he retires in 30 years?
  2. How much money will he have if he retires in 40 years?

Solutions

Let $m$ be Brandon's money, and $t$ be the number of years he has been invested for.

$$m(t) = 10000(1.06)^t$$

  1. $10000 * 1.06^{30} = 57434.91$
  2. $10000 * 1.06^{40} = 102857.18$

Fun fact:

In the real world, many financial investments do not exactly follow an exponential formula. Instead, they are stochastic processes. This means that their growth every year is random. However, over time, their growth pattern looks exponential. Other investments, like government bonds, grow exponentially.

In [4]:
x = np.arange(0,50,1)
y = 10000 * (1 + .06)**x
plotit(x,y)

S&P 500 Index

title

Group Problem 2

Jane also invests €10000 into her retirement account. Sadly for her, every year, her account shrinks by 6%

  1. How much money will she have if she retires in 30 years?
  2. How much money will she have if she retires in 40 years?

Solutions

Let $m$ be Jane's money, and $t$ be the number of years she has been invested for.

$$m(t) = 10000(1-.06)^t = 10000*.94^t$$

  1. $.94^{30} = 1562.5$
  2. $.94^{40} = 841.61$
In [5]:
x = np.arange(0,40,1)
y1 =10000* 1.06**x
y2= 10000*.94**x
plot_multiple([x,x],[y1,y2])

Logarithmic Functions

Recall that logarithms are the inverse of exponents.

$$log_b(x) = y \iff b^y = x$$

In [6]:
import math
vlog = np.vectorize(math.log)
x = np.arange(1,100,.1)
y1 = vlog(x,2)
y2 = vlog(x,3)
#x.apply
trace0 = go.Scatter(x=x, y=vlog(x,2), mode = 'lines', name = '$f(x)=log_2(x)$')
trace1 = go.Scatter(x=x, y=y2, mode = 'lines', name = '$f(x)=log_3(x)$')
trace2 = go.Scatter(x=x, y=vlog(x,4), mode = 'lines', name = '$f(x)=log_4(x)$')
traces = [trace0,trace1,trace2]
iplot(traces)
In [21]:
import math
vlog = np.vectorize(math.log)
x1 = np.arange(.0001,4,.0001)
x2 = np.arange(-5,4,.1)
y1 = vlog(x1,2)
y2 = 2**x2
#x.apply
trace0 = go.Scatter(x=x1, y=y1, mode = 'lines', name = '$f(x)=log_2(x)$')
trace1 = go.Scatter(x=x2, y=y2, mode = 'lines', name = '$f(x)=2^x$')
#trace2 = go.Scatter(x=x, y=vlog(x,4), mode = 'lines', name = '$f(x)=log_4(x)$')
traces = [trace0,trace1]#,trace2]
iplot(traces)
In [ ]:

Logarithms

  • Logarithms grow very very slowly.

Logarithm Review

  1. $$\text{log}_2(1/8)$$

  2. $$\text{log}_3(27)$$

  3. $$\text{log}_{10}(\frac{1}{100})$$

Domain and Range of a Logarithm

$$f(x) = \text{log}_2(x)$$

Domain : $x > 0$

Range : all real numbers

The domain and range of exponents and logarithms are opposite.